package top.lyc829.zzl_android.ui.base_detail;

import android.graphics.Color;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.module.LoadMoreModule;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xuexiang.xui.widget.button.shinebutton.ShineButton;
import com.xuexiang.xutil.data.DateUtils;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import top.lyc829.zzl_android.MyApp;
import top.lyc829.zzl_android.R;
import top.lyc829.zzl_android.logic.bean.BaseBean;
import top.lyc829.zzl_android.logic.bean.SuperCommentBean;

public class  CommentsAdapter extends BaseQuickAdapter<SuperCommentBean, BaseViewHolder> implements LoadMoreModule {

    public CommentsAdapter() {
        super(R.layout.comment_item);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SuperCommentBean superCommentBean) {
        baseViewHolder
                .setText(R.id.comment_item_username, superCommentBean.getUserName())
                .setText(R.id.comment_item_time, DateUtils.millis2String(Long.parseLong(superCommentBean.getCommentTime()) , DateUtils.yyyyMMdd.get()))
                .setText(R.id.comment_item_text, superCommentBean.getCommentText())
                .setText(R.id.comment_item_like_nums, String.valueOf(superCommentBean.getCommentLikes()))
                .setText(R.id.comment_item_go_replay, superCommentBean.getReplyNums() + "条回复 >");

        ImageView btnLike = baseViewHolder.getView(R.id.comment_item_like_btn);
        // 已经点赞
        if (superCommentBean.getIsLike().equals(1)) {
            btnLike.setImageResource(R.drawable.ic_baseline_thumb_up_red_20);
            ((TextView)baseViewHolder.getView(R.id.comment_item_like_nums)).setTextColor(Color.parseColor("#E54D42"));
        } else {
            btnLike.setImageResource(R.drawable.ic_baseline_thumb_up_gray_24);
            ((TextView)baseViewHolder.getView(R.id.comment_item_like_nums)).setTextColor(Color.parseColor("#8A000000"));
        }


        Glide.with(MyApp.getContext())
                .load(superCommentBean.getImgUrl())
                .into((ImageView) baseViewHolder.getView(R.id.comment_item_avatar));
    }
}
